import axios, {addHeader, getTimestamp, storage, token} from './axios'

export default {
  get (url, data = {}) {
    return new Promise((resolve, reject) => {
      let timestamp = getTimestamp()
      addHeader('X-Timestamp', timestamp)
      axios.get(url, {params: data})
        .then(res => {
          resolve(res.data)
        })
        .catch(err => {
          reject(err)
        })
    })
  },
  post (url, data = {}) {
    return new Promise((resolve, reject) => {
      let timestamp = getTimestamp()
      addHeader('X-Timestamp', timestamp)
      axios.post(url, data)
        .then(res => {
          resolve(res.data)
        })
        .catch(err => {
          reject(err)
        })
    })
  },
  header (key, value) {
    addHeader(key, value)
  },
  token (value = null) {
    return token(value)
  },
  storage (key, value = null) {
    return storage(key, value)
  }
}
